#include "StdAfx.h"
#include "LRCambassador.h"
#include "PDAserver.h"
#include "CallBack.h"
#include "RTIcommand.h"

using namespace rti1516;
using namespace net;

extern void appendText(const wchar_t* text);

LRCambassador::LRCambassador(void)
: pfamb(NULL), server(new PDAserver())
{
}

LRCambassador::~LRCambassador(void)
{
}

void LRCambassador::createFederationExecution(std::wstring const & federationExecutionName) 
{
	this->server->sendCommand(new RTIcommand("createFederationExecution"));
	appendText(L"createFederationExecution");	
}

void LRCambassador::joinFederationExecution 
	(std::wstring const & federateType,
	std::wstring const & federationExecutionName,
	PDAfederateAmbassador & federateAmbassador)
{
	this->server->sendCommand(new RTIcommand("joinFederationExecution"));
	this->pfamb = &federateAmbassador;
	appendText(L"joinFederationExecution");
}

void LRCambassador::resignFederationExecution()
{
	appendText(L"resignFederationExecution");
}

void LRCambassador::destroyFederationExecution 
	(std::wstring const & federationExecutionName)
{
	appendText(L"destroyFederationExecution");
}

void LRCambassador::updateAttributeValues()
{
	appendText(L"updateAttributeValues");
}

// listen to server for callbacks
bool LRCambassador::evokeCallback()
{
	CallBack* pcb = this->server->getCallBack();
	if(pcb != NULL)
	{
		pcb->visit(this->pfamb);
		return true;
	}	
	return false;
}
